/**
 * 
 */
package com.expense.listener;

import java.util.Calendar;
import java.util.TimerTask;

import javax.servlet.ServletContext;

import org.apache.log4j.Logger;

import com.expense.util.BackUpDB;
import com.expense.util.ConfigUtil;
import com.expense.util.SqlConfig;

/**
 * 定时任务调度
 * @author xj
 */
public class DbBackUpTask  extends TimerTask{
	public Logger logger = Logger.getLogger(this.getClass());
	private static final int C_SCHEDULE_HOUR   = ConfigUtil.C_SCHEDULE_HOUR; //C_SCHEDULE_HOUR表示(晚上12点，也即0点)。
	private static boolean isRunning = false; 
	private ServletContext context = null; 
	public DbBackUpTask(ServletContext context) { 
	       this.context = context; 
	} 
	public void run() { 
	        Calendar cal = Calendar.getInstance();         
	       if (!isRunning)  {            
	           if (C_SCHEDULE_HOUR == cal.get(Calendar.HOUR_OF_DAY)) {             
	                isRunning = true;                 
	                //context.log("开始执行指定任务");
	                logger.info("开始执行指定数据库备份任务");
	                 
	                //TODO 添加自定义的详细任务，以下只是示例 
	               /* int i = 0; 
	                while (i++ < 10) { 
	                    context.log("已完成任务的" + i + "/" + 10); 
	                } */
	                
	                BackUpDB backUpDB=new BackUpDB();
	        		backUpDB.backUpTablet_Logo(context,null);
	                
	  
	               isRunning = false; 
	               //context.log("指定任务执行结束");
	               logger.info("指定数据库备份任务执行结束");
	          }             
	       } else { 
	            //context.log("上一次任务执行还未结束"); 
	    	   logger.info("上一次任务执行还未结束");
	      } 
	    } 
	
}
